<?php
/**
 * Created by PhpStorm.
 * User: mars
 * Date: 2019/1/22
 * Time: 1:12 PM
 */

namespace api\controllers;


use api\models\Job;
use api\models\Order;
use yii\helpers\Url;
use Yii;
use yii\web\ServerErrorHttpException;

class JobController extends BaseController
{
    public $modelClass = 'api\models\Job';


    public function actions()
    {
        $actions = parent::actions();
//        unset($actions['create'],$actions['update']);
        return $actions;
    }


    public function actionCreate(){
        if ($this->checkAccess) {
            call_user_func($this->checkAccess, $this->id);
        }

        $model = new Job();

        $model->load(Yii::$app->getRequest()->getBodyParams(), '');
        $model->date = Yii::$app->getRequest()->getBodyParams();
        if ($model->save()) {
            $response = Yii::$app->getResponse();
            $response->setStatusCode(201);
            $id = implode(',', array_values($model->getPrimaryKey(true)));
            $response->getHeaders()->set('Location', Url::toRoute(['view', 'id' => $id], true));
        } elseif (!$model->hasErrors()) {
            throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
        }

        return $model;
    }

    //TODO:
    //
    public function actionUpdate(){

    }


}